package com.fw.ui.view.common;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.ui.util.VaadinApplicationObjectSupport;
import com.fw.ui.view.AbstractPanel;
import com.fw.ui.view.common.event.ToggleControlPanelToggleButtonClickListener;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.BaseTheme;
import com.vaadin.ui.themes.Reindeer;

@Component
@Scope(SCOPE_PROTOTYPE)
public class ToggleControlPanel extends AbstractPanel {

    private static final long serialVersionUID = -6277016090829174156L;

    @Autowired
    protected transient VaadinApplicationObjectSupport app;
    @Autowired
    private ToggleControlPanelToggleButtonClickListener toggleControlPanelToggleButtonClickListener;

    private HorizontalLayout layoutButton = new HorizontalLayout();
    protected Button btnTogglePanel = new Button();
    protected Button btnToggleButton = new Button();
    protected AbstractPanel panel;

    @Override
    public void init() {
	this.btnTogglePanel.setCaption("Click to Hide Search Criteria ... ");
	this.btnTogglePanel.setVisible(true);
	this.btnTogglePanel.setData(new Boolean(true));
	this.btnTogglePanel.setStyleName(BaseTheme.BUTTON_LINK);

	this.layoutButton.addComponent(this.btnTogglePanel);

	VerticalLayout vLayout = (VerticalLayout) this.getContent();
	vLayout.addComponent(this.layoutButton);
	this.setStyleName(Reindeer.PANEL_LIGHT);
    }

    public void setButtonDisplayCaption(String caption) {
	this.btnTogglePanel.setCaption(caption);
    }

    public void setButtonHideCaption(String caption) {
	this.btnTogglePanel.setCaption(caption);
    }

    public void setTogglePanel(AbstractPanel panel) {
	this.panel = panel;
    }

    public AbstractPanel getTogglePanel() {
	return this.panel;
    }

    public void setToggleButton(Button btnToggleButton) {
	this.btnToggleButton = btnToggleButton;
    }

    public Button getToggleButton() {
	return this.btnToggleButton;
    }

    public Button getTogglePanelButton() {
	return this.btnTogglePanel;
    }

    public void togglePanel() {
	Boolean data = (Boolean) this.btnTogglePanel.getData();
	HorizontalLayout hlayout = (HorizontalLayout) panel.getContent();
	if (data != null && data.booleanValue()) {
	    this.btnTogglePanel.setCaption("Click to Display Search Criteria ... ");
	    hlayout.setVisible(false);
	    this.btnToggleButton.setVisible(false);
	    this.btnTogglePanel.setData(new Boolean(false));
	} else {
	    this.btnTogglePanel.setCaption("Click to Hide Search Criteria ... ");
	    hlayout.setVisible(true);
	    this.btnToggleButton.setVisible(true);
	    this.btnTogglePanel.setData(new Boolean(true));
	}
    }

    @Override
    public void initListener() {
	this.toggleControlPanelToggleButtonClickListener.setBasedComponent(this);
	this.btnTogglePanel.addClickListener(this.toggleControlPanelToggleButtonClickListener);
    }

    @Override
    public void initValidator() {
	// TODO Auto-generated method stub
    }

    @Override
    public void initData() {
	// TODO Auto-generated method stub
	
    }

    @Override
    public void updateStrings() {
	// TODO Auto-generated method stub
	
    }

}
